#include "RaceQuest.h"
#include "CollisionManager.h"

RaceQuest::RaceQuest()
{
	//set null values for time limt and finsh line pos
	TimeLimit = 0.0f;
	InitialTimeLimit = 0.0f;
	FinishLine = XMFLOAT3(0.0f,0.0f,0.0f);
}

RaceQuest::~RaceQuest()
{

}
	
void RaceQuest::Intialise()
{
	//reset time limit and bools 
	TimeLimit = InitialTimeLimit;
	SetFailed(false);
	SetIsCompleted(false);
}

	
void RaceQuest::Update(float delta,XMFLOAT3 playerpos)
{
	//check whether the quest is still active
	if(!GetFailed() && !GetIsCompleted())
	{
			//get distance from player to finshline
			float temp = CollisionManager::GetInstance()->CalculateUnsignedDistance(FinishLine,playerpos);

			//if that distance is less than the radius of the collsionsphere
			if(temp < Radius)
			{
				//complete quest
				SetIsCompleted(true);
			}
		

		//lower time limit based on time since last frame
		TimeLimit -= delta;

		//if the time limt has run out and the quest has not already been completed
		if(TimeLimit <= 0 && !GetIsCompleted())
		{
			//set quest to failed
			SetFailed(true);
		}
	}
}

void RaceQuest::SetValues(XMFLOAT3 finish,float time,float radius)
{
	//set time limit and finsh line position
	FinishLine = finish;
	InitialTimeLimit = time;
	Radius = radius;
}